import initServerInstance from '../server/initServerInstance';

if (require.main === module) {
	(async () => {
		const server = await initServerInstance({
			loggerConfig: {
				name: 'upgrade',
				alwaysCreate: true,
			},
		});
		const { User, Balance, AlertReceiver } = server.app.model;

		for await (const user of User.find()) {
			const balance = await Balance.findOne({ uid: user._id });
			if ((balance.planExpireTime?.getTime() || 0) < Date.now()) continue;
			const receiver = await AlertReceiver.findOne({
				isDefault: true,
				uid: user._id,
			});
			if (!receiver) continue;
			// eslint-disable-next-line
			console.log(
				`${user.username},${receiver.emailVerified && receiver.email},${
					receiver.phoneVerified && receiver.phone
				}`
			);
		}

		process.exit();
	})();
}
